package com.android.gl2jni.filter;

import android.content.Context;
import com.android.gl2jni.GL2JNILib;
import com.android.gl2jni.ShaderUtils;

/**
 * Create time: 2018/9/15.
 */
public class MosaicFilterProgram extends TextureFilterProgram {
  private float mosaicSize = 10f;
  private int mosaicSizeLoc;
  private int miResolutionLoc;
  private int miTimeLoc;
  /**
   * Prepares the program in the current EGL context.
   */
  public MosaicFilterProgram(Context context) {
    super(context, ProgramType.TEXTURE_EXT);
  }

  @Override
  protected void initProgram() {
    super.initProgram();
    mosaicSizeLoc = getUniformLocation("mosaicSize");
    miResolutionLoc = getUniformLocation("iResolution");
    miTimeLoc = getUniformLocation("iTime");
  }

  @Override
  protected String getFragmentShaderSourceEXT() {
    return ShaderUtils.readAssetsTextFile(getContext(),
        "filter/fsh/shadertoy/voronoi.glsl");
  }

  @Override
  protected void onDraw(int firstVertex, int vertexCount) {
    setFloat(mosaicSizeLoc, mosaicSize);
    setFloat(miTimeLoc, System.currentTimeMillis());
    setFloatVec3(miResolutionLoc, new float[]{(float) surfaceWidth, (float) surfaceHeight, 1.0f});
    super.onDraw(firstVertex, vertexCount);
  }

  public void setMosaicSize(float mosaicSize) {
    this.mosaicSize = mosaicSize;
  }
}
